import pytest
import time
from selenium import webdriver
from poium import Page, Element


# 测试数据
test_data = [("****", "123456"), ("****", "123123")]

def pytest_generate_tests(metafunc):
    if "parameters" in metafunc.fixturenames:
        metafunc.parametrize(
            "parameters",
            test_data,
            ids=[],
            scope="function")
# 封装输入和点击的操作
class LoginPage(Page):
    account_tab = Element(css='span[data-type="tuzhan"]')
    input_user = Element(css='[placeholder="请输入你的登录账户"]')
    input_pwd = Element(css='[placeholder="请输入密码"]')
    login_button = Element(css='button.g-btn.login-btn.do-btn')

    def login(self, user, pwd):
        self.account_tab.click()
        self.input_user.input(user)
        self.input_pwd.input(pwd)
        self.login_button.click()


# 测试用例
def test_login(browser, parameters):
    browser.get("https://www.rabbitpre.com/")
    login_btn = browser.find_element_by_css_selector('#g-j-signin-btn')
    login_btn.click()
    login_iframe = browser.find_element_by_css_selector('#sso')
    browser.switch_to.frame(login_iframe)

    page = LoginPage(browser)
    phone = parameters[0]
    pwd = parameters[1]
    page.login(user=phone, pwd=pwd)
    time.sleep(2)
    assert page.get_title == "工作台-兔展"


if __name__ == '__main__':
    pytest.main(['-s', 'mengfeiyuan.py', '--html=report.html', '--self-contained-html'])
